package lib.common.use;

import java.util.HashMap;
import java.util.Map;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;

import com.app.BaseActivity;
import com.app.util.Utils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.yitong.service.APPResponseHandler;
import com.yitong.service.APPRestClient;
import com.yitong.service.YTRequestParams;

public class FucActivity extends BaseActivity {

	FucActivity activity = this;
	ImageView iv_logo;
	Button btn_load_pic;
	private Button btn_top_animation;
	
	
	LinearLayout layout_title;
	private Button btn_login;
	
	
	@Override
	public int InitLayout() {
		// TODO Auto-generated method stub
		requestWindowFeature( Window.FEATURE_NO_TITLE );
		return R.layout.activity_fuc;
	}

	@Override
	public void InitView() {
		// TODO Auto-generated method stub

		layout_title = (LinearLayout)findViewById(R.id.layout_title);
		
		
		iv_logo = (ImageView)findViewById(R.id.iv_logo);
		btn_load_pic = (Button)findViewById(R.id.btn_load_pic);
		btn_top_animation = (Button)findViewById(R.id.btn_top_animation);
	
		btn_login = (Button)findViewById(R.id.btn_login); 
	}

	@Override
	public void InitListener() {
		// TODO Auto-generated method stub

		
		btn_load_pic.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				Intent intent = new Intent(activity, DialogPhotoActivity.class);
				startActivity(intent);
				overridePendingTransition(android.R.anim.fade_in,
						android.R.anim.fade_out);
			}
		});
		
		btn_top_animation.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				final PopupWindow popup = new PopupWindow(activity);
				
				int height = layout_title.getHeight();
				
				View view = activity.getLayoutInflater().inflate(R.layout.popup_tip, null);
				popup.setContentView(view);
				popup.setWidth( LayoutParams.MATCH_PARENT );
				popup.setHeight( LayoutParams.WRAP_CONTENT );
				popup.setAnimationStyle(R.style.PopupAnimation_down_up);
				popup.showAsDropDown(layout_title, 0, 0);
				//popup.showAsDropDown( getWindow().getDecorView().getRootView() );
				
				
				new Thread(){
					public void run() {
						
						try {
							Thread.sleep(3000);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
						activity.runOnUiThread(new Runnable() {
							
							@Override
							public void run() {
								// TODO Auto-generated method stub
								popup.dismiss();
								System.out.println("popup.dismiss()");
							}
						});
						
					};
				}.start();
				
				
				
			}
		});
	
		
		
		btn_login.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				new Thread(){
					
					public void run() {
						
						  
						
						
					};
					
				}.start();
				
				requestLogin("13505171944", "123456", "", "");
				
			}
		});
		
		
	}

	@Override
	public void InitProcess() {
		// TODO Auto-generated method stub

		
		new Thread(){
			public void run() {
				String ip =  Utils.getIPAddress_fromtaobao();
				System.out.println(ip);
				
			}; 
			
		}.start();
	
		// 监听屏幕
		//Utils_Hardware.setListenerScreenStatus(activity);
		
		
		{
			
			DisplayImageOptions options = new DisplayImageOptions.Builder()
	        .showImageOnLoading(R.drawable.ic_launcher) // resource or drawable
	        .showImageForEmptyUri(R.drawable.ic_launcher) // resource or drawable
	        .showImageOnFail(R.drawable.ic_launcher) // resource or drawable
	        .resetViewBeforeLoading(false)  // default
	        //.delayBeforeLoading(1000)
	        .cacheInMemory(true) //  
	        .cacheOnDisc(true)  // 
	        .build();

			String url_pic = "http://www.baidu.com/img/bdlogo.png";
			//ImageLoader.getInstance().displayImage(url_pic, iv_logo);
			ImageLoader.getInstance().displayImage(url_pic, iv_logo, options);
			
			
			
			String pic_file = ImageLoader.getInstance().getDiscCache().get(url_pic).toString();
			System.out.println();
			
		}
		
		 
		
		
		
		
		
	}
	
	
	
	private void requestLogin(final String username, String passwd,
			String checkcode, String deviceId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userName", username);
		params.put("password", passwd);
		
		// 
		YTRequestParams requestParams = new YTRequestParams(
				YTRequestParams.PARAM_TYPE_FORM, params);
		APPRestClient.post("https://login.jiuxian.com",
				requestParams, new APPResponseHandler<LoginResult>(LoginResult.class) {
 
					@Override
					public void onSuccess(LoginResult result) {
						// TODO Auto-generated method stub

						Intent intent = null;
						if (result != null) {

						 
						}
					}

					@Override
					public void onFailure(String errorCode, String errorMsg) {
						// TODO Auto-generated method stub
					 
						System.out.println("onFailure");
						
					}
				});
	}
	
	
	
	/*
	class WaitTask extends AsyncTask<Void, Void, Void>
	{

		@Override
		protected Void doInBackground(Void... params) {
			// TODO Auto-generated method stub
			
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return null;
		}
		
		
		@Override
		protected void onPostExecute(Void result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			
			System.out.println("popup.dismiss()");
		}
	
	};
	*/
	
	

}
